package com.atguigu.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.atguigu.constant.MessageConstant;
import com.atguigu.entity.Result;
import com.atguigu.pojo.Setmeal;
import com.atguigu.service.SetmealService;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/pages/setmeal")
public class SetmealMobileController {


    @Reference
    private SetmealService setmealService;

    @PostMapping("getSetmeal")
    public Result getSetmeal(){
        try {
            List<Setmeal> list=setmealService.findAll();
            return new Result(true,MessageConstant.QUERY_SETMEALLIST_SUCCESS,list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_SETMEALLIST_FAIL);
        }
    }



    //根据id查询套餐信息
    @PostMapping("/findById")
    public Result findById(int id){
        try {
            Setmeal setmeal= setmealService.findByOne(id);
            return new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }

    //根据id查询套餐信息
    @PostMapping("/getSetmealById")
    public Result getSetmealById(int id){
        try {
            Setmeal setmeal= setmealService.getSetmealById(id);
            return new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }

}